<template>
  <div class="items">
    <h4 class="title">热门推荐</h4>
    <div class="item" @click="clickItem(item.id)" v-for="item in items" :key="item.id">
      <img :src="item.pic" alt="" class="item-thumb" />
      <div class="item-info">
        <h5>{{ item.name }}</h5>
        <div class="item-actions">
          <p class="price">￥{{ item.minPrice }}</p>
          <van-icon
            @click.stop="addCart(item.id)"
            name="gouwuchetianjia"
            size="20"
            class-prefix="icon"
          />
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import type { ItemType } from "../types/index";
defineProps<{
  items: ItemType[];
}>();
const emit = defineEmits<{
  (e: "enterDetail", id: number): void;
  (e: "addCart", id: number): void;
}>();

// 点击商品
const clickItem = (id: number) => {
  emit("enterDetail", id);
};
// 点击加入购物车图标
const addCart = (id: number) => {
  emit("addCart", id);
};
</script>

<style scoped lang="scss">
.items {
  .title {
    line-height: 30px;
    font-size: 18px;
    text-align: center;
    background-color: #f1f1f1;
  }
  .item {
    display: flex;
    img {
      width: 3rem;
    }
    .item-info {
      flex: 1;
      font-size: 14px;
      padding: 0 10px;
      h5 {
        line-height: 24px;
      }
      .item-actions {
        display: flex;
        align-items: center;
        justify-content: space-between;
        color: #e93323;
        .price {
          font-size: 20px;
        }
      }
    }
  }
}
</style>
